<?php

namespace Model;

use Extension\Tools;
use Handler\ZoneHandler;

class User {
	/**
	 *
	 * @var int
	 */
	private $m_Id;
	/**
	 * 账号
	 *
	 * @var string
	 */
	private $m_Name;
	/**
	 *
	 * @var string
	 */
	private $m_Nick;
	/**
	 * 金币数
	 *
	 * @var int
	 */
	private $m_Coin;
	/**
	 * 性别
	 *
	 * @var unknown
	 */
	private $m_Sex;
	/**
	 * 权限等级
	 *
	 * @var unknown
	 */
	private $m_Level;
	/**
	 * 心跳
	 *
	 * @var unknown
	 */
	public $m_HeartBeat;
	/**
	 *
	 * @var unknown
	 */
	private $m_Token;
	/**
	 *
	 * @var unknown
	 */
	private $m_ClientId;
	/**
	 * 房间ID
	 *
	 * @var unknown
	 */
	private $m_RoomId;
	/**
	 *
	 * @var unknown
	 */
	private $m_IsRobot;
	/**
	 *
	 * @var unknown
	 */
	public $m_CoinValue;
	/**
	 * 构造函数
	 */
	function __construct() {
	}
	/**
	 * 析构函数
	 */
	function __destruct() {
	}
	/**
	 * 初始化
	 *
	 * @param unknown $id        	
	 * @param unknown $name        	
	 * @param unknown $coin        	
	 * @param unknown $sex        	
	 * @param unknown $clientId        	
	 * @param bool $isRobot        	
	 */
	public function mb_Init($id, $name, $nick, $coin, $sex, $level, $clientId, $isRobot = false) {
		$this->m_Id = $id;
		$this->m_Name = $name;
		$this->m_Nick = $nick;
		$this->m_Coin = $coin * ZoneHandler::mb_GetInstance ()->m_CoinValue;
		$this->m_Sex = $sex;
		$this->m_Level = $level;
		$this->m_ClientId = $clientId;
		
		$this->m_RoomId = - 1;
		$this->m_Token = md5 ( $name . time () );
		$this->m_HeartBeat = time ();
		$this->m_IsRobot = $isRobot;
		
		$this->m_CoinValue = ZoneHandler::mb_GetInstance ()->m_CoinValue;
		
		if ($isRobot) {
			Tools::mb_LogResult ( "机器人【 $this->m_Name 】初始化成功！" );
		}
	}
	/**
	 * 重新初始化
	 *
	 * @param unknown $clientId        	
	 */
	public function mb_ReInit($clientId) {
		$this->m_ClientId = $clientId;
		$this->m_Token = md5 ( $this->m_Name . time () );
	}
	/**
	 * 获取用户数据
	 *
	 * @return number[]|string[]|\Model\unknown[]
	 */
	public function mb_GetData() {
		return array (
				'id' => $this->m_Id,
				'name' => $this->m_Name,
				'nick' => $this->m_Nick,
				'coin' => ( string ) $this->m_Coin,
				'sex' => $this->m_Sex,
				'level' => $this->m_Level,
				'room' => ( string ) $this->m_RoomId,
				'token' => $this->m_Token 
		);
	}
	/**
	 * 进入房间
	 *
	 * @param unknown $roomName        	
	 */
	public function mb_EnterRoom($roomId) {
		$this->m_RoomId = $roomId;
	}
	/**
	 * 退出房间
	 */
	public function mb_ExitRoom() {
		$this->m_RoomId = - 1;
	}
	/**
	 * 保存数据
	 *
	 * @param int $coin        	
	 */
	public function mb_Save($coin) {
		$this->m_Coin += $coin;
	}
	public function mb_Disconnect() {
		$this->m_ClientId = '';
	}
	public function __get($property_name) {
		if (isset ( $this->$property_name )) {
			return ($this->$property_name);
		} else {
			return (NULL);
		}
	}
	// public function __set($property_name, $val) {
	// $this->$property_name = $val;
	// }
}